import React, { Component } from "react";

export default class App extends Component {
    state = {
        firstName: '1',
        lastName: '2',
        note: ''
    }

    handler = (event) => {
        this.setState({
            [event.target.name]: event.target.value
        })
    }

    render() {
        return (
            <div>
                {/* 通过input的change事件改变 ,,事件委托*/}
                <input type="text" name="firstName" value={this.state.firstName} onChange={this.handler} /> +
                <input type="text" name="lastName" value={this.state.lastName} onChange={this.handler} /> =
                {Number(this.state.firstName) + Number(this.state.lastName)}

                <br />
                <textarea name="note" value={this.state.note} onChange={this.handler}></textarea>
                {this.state.note}
            </div>
        )
    }
}